/*     */ package com.wzh.action.tag;
/*     */ 
/*     */ import com.wzh.action.cache.CacheManager;
/*     */ import com.wzh.bean.book.BookType;
/*     */ import com.wzh.service.bookinfo.booktype.BookTypeService;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletResponse;
/*     */ import javax.servlet.jsp.JspException;
/*     */ import javax.servlet.jsp.PageContext;
/*     */ import javax.servlet.jsp.tagext.TagSupport;
/*     */ import org.apache.struts2.ServletActionContext;
/*     */ import org.springframework.web.context.WebApplicationContext;
/*     */ import org.springframework.web.context.support.WebApplicationContextUtils;
/*     */ 
/*     */ public class MenuTag extends TagSupport
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  26 */   private static CacheManager cacheManager = CacheManager.getInstance("menu");
/*     */ 
/*  29 */   private int num = 10;
/*     */   private String var;
/*     */   private Iterator<BookType> it;
/*  32 */   private StringBuilder cacheKey = new StringBuilder("");
/*     */ 
/*     */   public MenuTag()
/*     */   {
/*  37 */     int cachetime = -1;
/*  38 */     cacheManager.setRefreshPeriod(cachetime);
/*     */   }
/*     */ 
/*     */   private void init()
/*     */   {
/*  44 */     this.cacheKey.append("num_" + this.num);
/*     */ 
/*  49 */     Object obj = cacheManager.get(this.cacheKey.toString());
/*     */ 
/*  52 */     if (obj != null) {
/*  53 */       List bookTypes = (List)obj;
                if(bookTypes.size()>0) {
                    this.it = bookTypes.iterator();
                     this.cacheKey.delete(0, this.cacheKey.length());
                     return;
                }
/*     */     }
/*     */ 
/*  61 */     WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
/*  62 */     BookTypeService bookTypeService = (BookTypeService)wac.getBean("bookTypeServiceBean");
/*     */ 
/*  65 */     List bookTypes = bookTypeService.getMenus(this.num);
/*  66 */     this.it = bookTypes.iterator();
/*     */ 
/*  69 */     cacheManager.put(this.cacheKey.toString(), bookTypes);
/*     */ 
/*  71 */     this.cacheKey.delete(0, this.cacheKey.length());
/*     */   }
/*     */ 
/*     */   public String getVar() {
/*  75 */     return this.var;
/*     */   }
/*     */ 
/*     */   public void setVar(String var)
/*     */   {
/*  80 */     this.var = var;
/*     */   }
/*     */ 
/*     */   public int getNum()
/*     */   {
/*  85 */     return this.num;
/*     */   }
/*     */ 
/*     */   public void setNum(int num)
/*     */   {
/*  90 */     this.num = num;
/*     */   }
/*     */ 
/*     */   public int doStartTag()
/*     */     throws JspException
/*     */   {
/*  97 */     init();
/*     */ 
/*  99 */     this.pageContext.getResponse().setCharacterEncoding("utf-8");
/* 100 */     if ((this.it != null) && (this.it.hasNext())) {
/* 101 */       this.pageContext.setAttribute(this.var, this.it.next());
/* 102 */       return 1;
/*     */     }
/* 104 */     return 0;
/*     */   }
/*     */ 
/*     */   public int doAfterBody()
/*     */     throws JspException
/*     */   {
/* 110 */     if ((this.it != null) && (this.it.hasNext())) {
/* 111 */       this.pageContext.setAttribute(this.var, this.it.next());
/*     */ 
/* 113 */       return 2;
/*     */     }
/* 115 */     return 0;
/*     */   }
/*     */ 
/*     */   public int doEndTag()
/*     */     throws JspException
/*     */   {
/* 122 */     this.pageContext.removeAttribute(this.var);
/* 123 */     this.pageContext.removeAttribute("costtime");
/* 124 */     return 6;
/*     */   }
/*     */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.action.tag.MenuTag
 * JD-Core Version:    0.6.1
 */